import streamlit as st
import data.data as dd
import time

st.set_page_config(
    page_title='私人助手登录页面',
    page_icon='😍',
)
st.title('私人助手登录页面')
username = st.text_input('请输入用户名')
password = st.text_input('请输入密码',type='password')
login_flag = st.button("登录")


if login_flag:
    if username and password:
        flag = dd.query_user_no_exists(username)
        if flag is True:
            st.error('请检查用户名是否书写正确!')
        else:
            passwd = dd.query_user_pass(username)
            if passwd == password:
                st.success("登录成功!")
                time.sleep(2)
                st.switch_page("pages/chatbot.py")
            else:
                st.error('密码错误,请重新输入!')
    else:
        st.error('请务必填写登录信息!')

register_flag = st.button("没有账号？点击注册")
if register_flag:
    st.switch_page("pages/register.py")